<?php
require_once 'PHPUnit/Framework.php';
require 'TVB/PWORKS/util/CommonUtil.class.php';

class ImageUpdateActionTest extends PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        $this->url = 'http://pdes.tvb.com/update_image.html?act=edit&ut=true';
    }

    protected function tearDown()
    {
        unset($this->url);
    }

    function testSucess()
    {
        $param = array(
            'id'                    => '88',
            'title'                 => 'Donald UT',
            'online_date_time[0]'   => '2010-01-21',
            'online_date_time[1]'   => '11:20',
            'offline_date_time[0]'  => '2010-01-30',
            'offline_date_time[1]'  => '11:21',
            'country_allow_deny'    => 'allow',
            'country[]'             => 'HK',
            'modified_at'           => '',
            'copyright'             => 'Other',
            'mdes_status'           => '3',
            'langid'                => '',
            'reset'                 => '', 
            'from'                  => '',
            'cast_dictionary_id[0]' => '1',
            'cast_dictionary_id[1]' => '2',
            'tag'                   => '',
            'new_tag'               => '',
            'tags'                  => '',
        );
        $ret = CommonUtil::curl_test($this->url, $param);
        $ret = json_decode($ret);
        $error_count = count($ret);
        if ($error_count >0) {
            #var_export($ret);
        }
        $this->assertEquals($error_count, 0);
    }

    function testFilterFailur()
    {
        $param = array(
            'id'                    => '88',
            'online_date_time[0]'   => 'error',
            'online_date_time[1]'   => '11:20',
            'offline_date_time[0]'  => 'error',
            'offline_date_time[1]'  => '11:21',
        );
        $ret = CommonUtil::curl_test($this->url, $param);
        $ret = json_decode($ret);
        $error_count = count($ret);
        if ($error_count>0) {
            #var_export($ret);
        }
        $this->assertEquals($error_count, 2);
    }

    function testOnlineOfflineDateTime()
    {
        $param = array(
            'id'                    => '88',
            'online_date_time[0]'   => '2010-01-31',
            'online_date_time[1]'   => '11:20',
            'offline_date_time[0]'  => '2010-01-30',
            'offline_date_time[1]'  => '11:21',
        );
        $ret = CommonUtil::curl_test($this->url, $param);
        $ret = json_decode($ret);
        $error_count = count($ret);
        if ($error_count>0) {
            #var_export($ret);
        }
        $this->assertEquals($error_count, 1);
    }
}
?>
